package com.his.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.his.admin.service.SectionService;
import com.his.dao.domain.dto.ListDto;
import com.his.dao.domain.entity.Medicine;
import com.his.dao.domain.entity.Section;
import com.his.dao.domain.vo.ListVo;
import com.his.dao.mapper.MedicineMapper;
import com.his.dao.mapper.SectionMapper;
import com.his.util.result.RestResult;
import com.his.util.result.RestResultBuilder;
import com.his.util.util.MapUtil;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fall
 * @since 2022-11-28
 */
@Service
@AllArgsConstructor
public class SectionServiceImpl extends ServiceImpl<SectionMapper, Section> implements SectionService {
    private SectionMapper sectionMapper;

    @Override
    public RestResult all(ListDto listDto) {
        Section section = MapUtil.conversionMapToObj((Map) listDto.getObj(),Section.class);
        return new RestResultBuilder().success(ListVo
                .builder()
                .list(sectionMapper.selectAll(
                        section.getName(),
                        section.getHospitalId(),
                        listDto.getPage() * listDto.getPageSize(),
                        listDto.getPageSize()
                ))
                .total(sectionMapper.selectAllCount(
                        section.getName(),
                        section.getHospitalId()
                ))
                .build());
    }

    @Override
    public RestResult allId(Section section) {
        QueryWrapper<Section> queryWrapper = new QueryWrapper<Section>()
                .select("section_id", "name")
                .like(section.getName() != null,"name",section.getName())
                .eq(section.getHospitalId() != null,"hospital_id",section.getHospitalId());
        return new RestResultBuilder().success(sectionMapper.selectList(queryWrapper));
    }

}
